using Infrastructure.Attribute;
using Infrastructure.Extensions;
using JTZY.Model.Goods.Dto;
using JTZY.Model.Goods;
using JTZY.Repository;
using JTZY.Service.Goods.IGoodsService;
using JTZY.ServiceCore.Services;
using JTZY.Common;
using Microsoft.IdentityModel.Tokens;
using System.Net.WebSockets;
using static StackExchange.Redis.Role;
using JTZY.Model.Content.Dto;
using JTZY.Service.Product.IProductService;
using JTZY.Model.Product;
using JTZY.Common.Utils;
using CommonUtils;
using System.Text;
using JTZY.Service.Product;
using JTZY.Service.Business.IBusinessService;
using JTZY.Service.Business;
using Infrastructure;
using System.Runtime.CompilerServices;

namespace JTZY.Service.Goods
{
    /// <summary>
    /// checkstockService业务层处理
    /// </summary>
    [AppService(ServiceType = typeof(IStocklogmasterService), ServiceLifetime = LifeTime.Transient)]
    public class StocklogmasterService : BaseService<Stocklogmaster>, IStocklogmasterService
    {
        private IProdinfoService _prodinfoService;
        private ICorecmsproductsService _corecmsproductsService;
        private ICorecmsuserService _corecmsuserService;
        private ICorecmsagentproductsService _corecmsagentproductsService;
        public StocklogmasterService(IProdinfoService prodinfoService, ICorecmsproductsService corecmsproductsService, ICorecmsuserService corecmsuserService, ICorecmsagentproductsService corecmsagentproductsService)
        {
            _prodinfoService = prodinfoService;
            _corecmsproductsService = corecmsproductsService;
            _corecmsuserService = corecmsuserService;
            _corecmsagentproductsService = corecmsagentproductsService;
        }


        /// <summary>
        /// 添加checkstock
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public Stocklogmaster AddStocklogmaster(Stocklogmaster model)
        {
            return Insertable(model).ExecuteReturnEntity();
        }

        /// <summary>
        /// 修改checkstock
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int UpdateStocklogmaster(Stocklogmaster model)               
        {
            return Update(model, true);
        }

        /// <summary>
        /// 查询导出表达式
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        private static Expressionable<Stocklogmaster> QueryExp(StocklogmasterQueryDto parm)
        {
            var predicate = Expressionable.Create<Stocklogmaster>();

            //predicate = predicate.AndIF(parm.BeginCreateDate == null, it => it.CreateDate >= DateTime.Now.ToShortDateString().ParseToDateTime());
            //predicate = predicate.AndIF(parm.BeginCreateDate != null, it => it.CreateDate >= parm.BeginCreateDate);
            //predicate = predicate.AndIF(parm.EndCreateDate != null, it => it.CreateDate <= parm.EndCreateDate);
            predicate = predicate.AndIF(parm.BeginCreateDate == null, it => it.CreateDate >= DateTime.Now.AddDays(-365).ToShortDateString().ParseToDateTime());
            predicate = predicate.AndIF(parm.BeginCreateDate != null, it => it.CreateDate >= parm.BeginCreateDate);
            predicate = predicate.AndIF(parm.EndCreateDate != null, it => it.CreateDate <= parm.EndCreateDate);
            return predicate;
        }

        public List<StockPdTreeDto> GetCategoryTree(long userId)
        {
            var query = Context.Queryable<Corecmsusergoods>()
                .Where(e => e.UserId == userId)
                .InnerJoin<Corecmsuserstock>((goods, stock) => goods.GoodId == stock.GoodId && goods.UserId == stock.UserId && stock.IsDel == false)
                .Select((goods, stock) => new StockPdDto()
                {
                    Id = goods.Id,
                    GoodId = goods.GoodId,
                    GoodName = goods.GoodName,
                    ProductId = stock.ProductId,
                    ProductName = string.IsNullOrEmpty(stock.SkuName) ? "未知名称" : stock.SkuName,
                    StockId = stock.Id
                }).ToList();
            List<StockPdTreeDto> list = new List<StockPdTreeDto>();
            foreach (var item in query)
            {
                var first = list.FirstOrDefault(e => e.id == item.GoodId);
                if (first == null)
                {
                    list.Add(new StockPdTreeDto()
                    {
                        id = item.GoodId,
                        name = item.GoodName,
                        children = new List<StockPdTreeDto>() { new StockPdTreeDto() {
                     id=item.ProductId,name=item.ProductName
                    } }
                    });
                }
                else
                {
                    first.children.Add(new StockPdTreeDto()
                    {
                        id = item.ProductId,// item.StockId,
                        name = item.ProductName
                    });
                }

            }
            return list;
        }

        /// <summary>
        /// 查询盘点范围的商品
        /// </summary>
        /// <param name="parm"></param>
        public StockPdSheetDto QueryStockProdByProdId(StockPdRangeQueryDto parm)
        {
            var goodId = parm.prodId;
            var skuCodes = parm.skuCodes;
            var result = Context.Queryable<Corecmsusergoods>()
                .Where(e => e.UserId == parm.userId)
                .InnerJoin<Corecmsgoods>((usergoods, goods) => usergoods.GoodId == goods.Id)
                .LeftJoin<Corecmsuserstock>((usergoods, goods, stock) => usergoods.GoodId == goods.Id && goods.Id == stock.GoodId && usergoods.UserId == stock.UserId && stock.IsDel == false)
                .Where((usergoods, goods, stock) => stock.GoodId == parm.prodId && parm.skuCodes.Contains(stock.ProductId))
                .Select((usergoods, goods, stock) => new
                {
                    categoryArr = goods.categoryArr,
                    goodsPic = goods.Image,
                    goodsId = goods.Id.ToString(),
                    goodsName = goods.Name,
                    inventoryQuantity = stock.Stock,
                    skuImage = stock.SkuImage,
                    skuId = stock.Id,
                    skuCode = string.IsNullOrEmpty(stock.BarCode) ? stock.Sn : stock.BarCode,
                    skuName = stock.SkuName,
                    productId = stock.ProductId
                }).ToList();
            StockPdSheetDto dto = new StockPdSheetDto();

            var first = result.FirstOrDefault();
            if (first == null) throw new Exception("无法找到货品");
            //类别
            if (!string.IsNullOrEmpty(first.categoryArr))
            {
                var categoryArr = first.categoryArr.Split(",");
                var categoryList = Context.Queryable<Corecmsgoodscategory>().Where(e => categoryArr.Contains(e.Id.ToString())).ToList();
                for (var i = 0; i < categoryArr.Length; i++)
                {
                    var firstCategory = categoryList.FirstOrDefault(e => e.Id.ToString() == categoryArr[i]);
                    if (firstCategory != null)
                    {
                        dto.categoryName += firstCategory.Name + "/";
                    }
                }
            }
            if (dto.categoryName != "") dto.categoryName = dto.categoryName.TrimEnd('/');
            dto.skuNum = result.Count();
            dto.pic = first.goodsPic;
            dto.prodId = first.goodsId;
            dto.prodName = first.goodsName;


            foreach (var item in result)
            {
                StockPdSheetSkuDetailsDto detail = new StockPdSheetSkuDetailsDto()
                {
                    inventoryQuantity = item.inventoryQuantity ?? 0,
                    pic = item.skuImage,
                    prodInventoryId = item.skuId,
                    skuCode = item.skuCode,
                    skuName = item.skuName,
                    quantity = 0,
                    differenceQuantity = item.inventoryQuantity ?? 0,
                    desc = ((item.inventoryQuantity ?? 0) == 0) ? "是" : "否",
                    //goodsId = item.goodsId,
                    productId = item.productId
                };
                dto.skuDtoList.Add(detail);
            }
            return dto;
        }


        public StockPdSheetDto SavePdSheet(long userId, StockPdSheetDto parm)
        {
            var master = new Stocklogmaster();
            master.CreateDate = DateTime.Now;
            master.StockMonth = DateTime.Now.ToString("yyyy-MM");
            master.Status = "0";
            master.userId = userId;
            master.CheckCount = parm.skuNum;
            master.NormalCount = parm.skuDtoList.Count(e => e.differenceQuantity == 0);
            master.goodsId = int.Parse(parm.prodId);
            var diffsum = parm.skuDtoList.Sum(e => e.quantity - e.inventoryQuantity);
            if (diffsum > 0) master.Profit = diffsum;
            else master.Loss = Math.Abs(diffsum);

            var masterId = Context.Insertable<Stocklogmaster>(master).ExecuteReturnBigIdentity();

            var listdetails = new List<Stocklogdetail>();
            for (var i = 0; i < parm.skuDtoList.Count; i++)
            {
                var detail = new Stocklogdetail();
                detail.masterId = masterId;
                detail.productId = parm.skuDtoList[i].productId;
                detail.sn = parm.skuDtoList[i].skuCode;
                detail.skuName = parm.skuDtoList[i].skuName;
                detail.stockQty = parm.skuDtoList[i].inventoryQuantity;
                detail.pdQty = parm.skuDtoList[i].quantity;
                detail.diffQty = parm.skuDtoList[i].differenceQuantity;
                listdetails.Add(detail);
            }
            Context.Insertable<Stocklogdetail>(listdetails).ExecuteCommand();

            parm.id = masterId;
            for (var i = 0; i < parm.skuDtoList.Count; i++)
            {
                parm.skuDtoList[i].prodInventoryId = masterId;
            }

            return parm;
        }
        /// <summary>
        /// 删除盘点记录
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="masterId"></param>
        /// <returns></returns>
        public bool DelPdSheet(long userId, long masterId)
        {
            Context.Deleteable<Stocklogdetail>().Where(e => e.masterId == masterId).ExecuteCommand();
            return Context.Deleteable<Stocklogmaster>().Where(e => e.StockId == masterId).ExecuteCommand() > 0;
        }

        /// <summary>
        /// 编辑盘点记录
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="parm"></param>
        /// <returns></returns>
        public StockPdSheetDto EditPdSheet(long userId, StockPdSheetDto parm)
        {
            var masterId = parm.id;
            var master = Context.Queryable<Stocklogmaster>().Where(e => e.StockId == masterId).First();
            var details = Context.Queryable<Stocklogdetail>().Where(e => e.masterId == masterId).ToList();

            master.NormalCount = parm.skuDtoList.Count(e => e.differenceQuantity == 0);
            var diffsum = parm.skuDtoList.Sum(e => e.quantity - e.inventoryQuantity);
            if (diffsum > 0) master.Profit = diffsum;
            else master.Loss = Math.Abs(diffsum);
            for (var i = 0; i < parm.skuDtoList.Count; i++)
            {
                var first = details.First(e => e.Id == parm.skuDtoList[i].id);
                first.pdQty = parm.skuDtoList[i].quantity;
                first.diffQty = parm.skuDtoList[i].differenceQuantity;
            }
            Context.Updateable<Stocklogmaster>(master).UpdateColumns(e => new { e.NormalCount, e.Loss, e.Profit }).ExecuteCommand();
            Context.Updateable<Stocklogdetail>(details).UpdateColumns(e => new { e.pdQty, e.diffQty }).ExecuteCommand();

            return parm;
        }

        /// <summary>
        /// 审核盘点单
        /// </summary>
        /// <param name="userId"></param>
        public bool ApprovePdSheet(long userId, long masterId)
        {
            var stockentities = Context.Queryable<Stocklogmaster>().Where(e => e.StockId == masterId)
                                .InnerJoin<Stocklogdetail>((master, detail) => master.StockId == detail.masterId)
                                .InnerJoin<Corecmsuserstock>((master, detail, stock) => master.goodsId == stock.GoodId && detail.productId == stock.ProductId && stock.UserId == userId)
                                .Select((master, detail, stock) => new
                                {
                                    quantity = detail.pdQty,
                                    master = master,
                                    stock = stock,
                                }).ToList();
            foreach (var stock in stockentities)
            {
                stock.stock.Stock = stock.quantity;
                stock.stock.SaleStock = stock.quantity;
            }
            var master = stockentities.First().master;
            master.Status = "1";
            master.NormalCount = master.CheckCount;
            Context.Updateable<Stocklogmaster>(master).UpdateColumns(e => new { e.Status, e.NormalCount }).ExecuteCommand();
            //Context.Updateable<Corecmsuserstock>(stockentities.Select(e => e.stock).ToList()).UpdateColumns(e => new { e.Stock,e.SaleStock }).ExecuteCommand();
            return true;
        }
        public PagedInfo<StocklogExportDto> ExportList(long userId, StocklogmasterQueryDto parm)
        {
            var predicate = QueryExp(parm);

            var response = Queryable()
                .Where(predicate.ToExpression())
                .Where(e => e.userId == userId && e.StockId == parm.Id)
                .InnerJoin<Stocklogdetail>((master, detail) => master.StockId == detail.masterId)
                .LeftJoin<Corecmsusergoods>((master, detail, goods) => master.goodsId == goods.Id)
                .Select((master, detail, goods) => new StocklogExportDto()
                {
                    goodsName = goods.GoodName,
                    prodName = detail.skuName,
                    sn = detail.sn,
                    stockQty = detail.stockQty,
                    pdQty = detail.pdQty,
                    dataStatus = "正常",
                    barCdoe = "",
                }, true)
                .ToPage(parm);

            return response;
        }

        public PagedInfo<StocklogmasterDto> ExportMasterList(long userId, StocklogmasterQueryDto parm)
        {
            parm.userId = userId;
            var pageinfo = GetList(parm);

            foreach (var item in pageinfo.Result)
            {
                item.StatusLabel = "正常";
            }
            return pageinfo;
        }
        /// <summary>
        /// 新增时是否有未完成的盘点记录
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public bool HasNotCheckedPdSheet(long userId)
        {
            var entities = Context.Queryable<Stocklogmaster>().Where(e => e.Status == "0" && e.userId == userId);

            return entities.Count() > 0;
        }
        /// <summary>
        /// 查询checkstock列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public PagedInfo<StocklogmasterDto> GetList(StocklogmasterQueryDto parm)
        {
            var predicate = QueryExp(parm);

            //if (!string.IsNullOrEmpty(parm.createTime))
            //{
            //    DateTime date;
            //    if (DateTime.TryParse(parm.createTime, out date))
            //    {
            //        parm.BeginCreateDate = new DateTime(date.Year, date.Month, date.Day);
            //        parm.EndCreateDate = new DateTime(date.Year, date.Month, date.Day, 23, 59, 59, 997);
            //        predicate.And(e => e.CreateDate >= parm.BeginCreateDate && e.CreateDate <= parm.EndCreateDate);
            //    }
            //}

            var response = Queryable().Where(e => e.userId == parm.userId)
                .Where(predicate.ToExpression())
                .LeftJoin<Corecmsgoods>((master, goods) => master.goodsId == goods.Id).WhereIF(!string.IsNullOrEmpty(parm.goodsName), (master, goods) => goods.Name.Contains(parm.goodsName))
                .SelectMergeTable<StocklogmasterDto>((master, goods) => new StocklogmasterDto()
                {
                    StockId = master.StockId,
                    CategoryName = goods.categoryArr,
                    goodsName = goods.Name,
                    imageUrl = goods.Image,
                    Status = master.Status,
                    StockMonth = master.StockMonth,
                    CreateDate = master.CreateDate,
                    Loss = master.Loss,
                    Profit = master.Profit ?? 0,
                    CheckCount = master.CheckCount,
                    NormalCount = master.NormalCount
                })
                .ToPage<StocklogmasterDto>(parm);

            var categoryIds = response.Result.Select(e => e.CategoryName).ToList();

            if (categoryIds.Count() > 0)
            {
                var categoryArr = new List<string>();
                categoryIds.ForEach(e => categoryArr.AddRange(e.Split(',')));

                var categoryList = Context.Queryable<Corecmsgoodscategory>().Where(e => categoryArr.Contains(e.Id.ToString())).ToList();
                foreach (var dto in response.Result)
                {
                    var categoryArrOne = dto.CategoryName.Split(',');
                    dto.CategoryName = "";
                    for (var i = 0; i < categoryArrOne.Length; i++)
                    {
                        var firstCategory = categoryList.FirstOrDefault(e => e.Id.ToString() == categoryArr[i]);
                        if (firstCategory != null)
                        {
                            dto.CategoryName += firstCategory.Name + "/";
                        }
                    }
                    if (!string.IsNullOrEmpty(dto.CategoryName))
                        dto.CategoryName = dto.CategoryName.TrimEnd('/');
                }
            }
            return response;
        }
        /// <summary>
        /// 获取详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public StockPdSheetDto GetInfo(long userId, long stockId)
        {
            var dto = new StockPdSheetDto();

            var response = Queryable().Where(x => x.StockId == stockId)
                .InnerJoin<Stocklogdetail>((master, detail) => master.StockId == detail.masterId)
                .LeftJoin<Corecmsgoods>((master, detail, goods) => master.goodsId == goods.Id)
                .LeftJoin<Corecmsuserstock>((master, detail, goods, stock) => master.goodsId == stock.GoodId && detail.productId == stock.ProductId && stock.UserId == userId)
                .Select((master, detail, goods, stock) => new
                {
                    Id = master.StockId,
                    categoryArr = goods.categoryArr,
                    dataStatus = master.Status,
                    pic = goods.Image,
                    prodId = goods.Id,
                    prodName = goods.Name,
                    skuNum = master.CheckCount,
                    differenceQuantity = detail.diffQty,
                    detailId = detail.Id,
                    inventoryQuantity = detail.stockQty,
                    detailPic = stock.SkuImage,
                    prodInventoryId = master.StockId,
                    quantity = detail.pdQty,
                    skuCode = detail.sn,
                    skuName = detail.skuName,
                    productId = detail.productId,
                }).ToList();

            var masterInfo = response.First();

            dto.skuNum = masterInfo.skuNum ?? 0;
            dto.finishedNum = response.Count().ToString();
            dto.id = masterInfo.Id;
            dto.pic = masterInfo.pic;
            dto.prodId = masterInfo.prodId.ToString();
            dto.prodName = masterInfo.prodName;
            dto.status = masterInfo.dataStatus;
            if (dto.status == "1")
            {
                dto.abnormalNum = "0";
            }
            //类别
            if (!string.IsNullOrEmpty(masterInfo.categoryArr))
            {
                var categoryArr = masterInfo.categoryArr.Split(",");
                var categoryList = Context.Queryable<Corecmsgoodscategory>().Where(e => categoryArr.Contains(e.Id.ToString())).ToList();
                for (var i = 0; i < categoryArr.Length; i++)
                {
                    var firstCategory = categoryList.FirstOrDefault(e => e.Id.ToString() == categoryArr[i]);
                    if (firstCategory != null)
                    {
                        dto.categoryName += firstCategory.Name + "/";
                    }
                }
            }
            for (var i = 0; i < response.Count; i++)
            {
                dto.skuDtoList.Add(new StockPdSheetSkuDetailsDto()
                {
                    differenceQuantity = response[i].differenceQuantity,
                    pic = response[i].detailPic,
                    id = response[i].detailId,
                    inventoryQuantity = response[i].inventoryQuantity,
                    productId = response[i].productId,
                    quantity = response[i].quantity,
                    skuCode = response[i].skuCode,
                    skuName = response[i].skuName,
                    prodInventoryId = masterInfo.Id
                });
            }
            return dto;
        }


        /// <summary>
        /// 获取物码信息
        /// </summary>
        /// <param name="snCode"></param>
        /// <returns></returns>
        public async Task<WebApiCallBack> GetProdInfo(string snCode, long userId)
        {
            var jm = new WebApiCallBack();
            #region 暂时弃用
            /*
            var no = "";
            var url = "";
            var f = "";
            var sign = TimeHelper.ToUnixTimestampBySeconds(DateTime.Now);
            if (snCode.Contains("http"))
            {
                var Querys = UrlStringHelper.GetQueryDictionary(snCode);
                no = Querys["no"];
                f = Querys["f"];
                if (f.ToLower() != "w")
                {
                    if (f.ToLower() != "w")
                    {
                        jm.status = false;
                        jm.msg = "商品打包请扫盒子码";
                        return jm;
                    }
                }
            }
            else
            {
                no = snCode;
            }
            Prodinfo info = null;
            url = $"https://www.ewmsy.com/c22/c376/getab382.ashx?gs=382&no={no}&f={f}&sign={sign}";
            string barCode = string.Empty;
            string nCode = string.Empty;
            try
            {
                var rsp = await (new HttpUtils().GetWebRequest(url, "post")).GetResponseAsync();//.HttpPostJson(url,).PostAsync().ReceiveJson<EwmsyResult>();
                string strRst = "";
                using (Stream stream = rsp.GetResponseStream())
                {
                    int size = 1024;
                    int read = 0;
                    byte[] by = new byte[800];
                    using (MemoryStream ms = new MemoryStream())
                    {
                        byte[] buffer = new byte[size];
                        do
                        {
                            read = stream.Read(buffer, 0, size);
                            ms.Write(buffer, 0, read);
                        } while (read > 0);

                        by = ms.ToArray();
                    }
                    strRst = Encoding.UTF8.GetString(by);
                }
                var result = JsonConvert.DeserializeObject<EwmsyResult>(strRst);
                if (result != null && result.success != "1")
                {
                    jm.status = false;
                    jm.msg = result.msg;
                    return jm;
                }
                else
                {
                    var arr = result.datas.Split(',');
                    info = new Prodinfo();
                    info.UserId = userId;

                    info.SnCode = arr[0];
                    barCode = arr[6];
                    info.NCode = arr[7];
                    info.ProdctDate = !string.IsNullOrEmpty(arr[1]) ? Convert.ToDateTime(arr[1]) : null;
                    if (!string.IsNullOrEmpty(arr[3]))
                    {
                        info.ActivationDate = Convert.ToDateTime(arr[3]);
                    }
                }

                if (info != null)
                {

                    var prodct = await _corecmsproductsService.GetFirstAsync(p => p.Barcode == barCode && p.IsDel == false);
                    if (prodct == null)
                    {
                        jm.status = false;
                        jm.msg = "没有商品信息";
                        return jm;
                    }
                    info.ProductId = prodct.Id;
                    try
                    {
                        info.QrCode = !string.IsNullOrEmpty(snCode) ? snCode : "";
                        var user = _corecmsuserService.GetById(userId);
                        var agent = await _corecmsagentproductsService.GetFirstAsync(e => e.UserId == userId && e.ProductId == prodct.Id);
                        if (agent != null)
                        {
                            info.CostPrice = agent.ProductCostPrice;
                        }
                        info.StoreId = user.StoreId ?? 0;
                        info.IsReturn = 0;
                        info.Status = 0;
                        info.InboundTime = DateTime.Now;
                        info.Agent = userId;
                        info.GoodsId = prodct.GoodsId;
                        await _prodinfoService.InsertAsync(info);
                    }
                    catch { }
            */
            #endregion
            try
            {
                if (snCode.Contains("http"))
                {
                    var Querys = UrlStringHelper.GetQueryDictionary(snCode);
                    snCode = Querys["no"];

                }

                var prodct = await _prodinfoService.AsQueryable().Where(e => e.SnCode == snCode && e.UserId == userId&&e.IsReturn==0)
                .InnerJoin<Corecmsproducts>((prodinfo, prod) => prodinfo.ProductId == prod.Id)
                .Select((prodinfo, prod) => new
                {
                    SpesDesc = prod.SpesDesc,
                    Sn = prod.Sn,   
                    productId = prodinfo.ProductId,
                    SnCode = prodinfo.SnCode,
                    UserCusId = prodinfo.UserCusId,
                    IsReturn = prodinfo.IsReturn,
                    Status = prodinfo.Status,
                }).FirstAsync();
                if (prodct == null)
                {
                    jm.status = false;
                    jm.msg = "未获取到物码信息";
                    return jm;
                }

                if (prodct.UserCusId.HasValue && prodct.UserCusId.Value > 0)
                {
                    jm.status = false;
                    jm.msg = "小仓商品，请先调回本仓再盘点";
                    return jm;
                }

                if (prodct.IsReturn==1)
                {
                    jm.status = false;
                    jm.msg = "退货次品，请勿盘点";
                    return jm;
                }

                if (prodct.Status == 2)
                {
                    jm.status = false;
                    jm.msg = "此商品已出库，请勿盘点";
                    return jm;
                }

                jm.data = new
                {
                    // name=goods.name,
                    addon = prodct.SpesDesc,
                    sn = prodct.Sn,
                    snCode = prodct.SnCode,
                    productId = prodct.productId,
                    nums = 1
                };
                jm.status = true;
                //}

                return jm;
            }
            catch (Exception ex)
            {
                jm.status = false;
                jm.msg = "未获取到物码信息";
                return jm;
            }
        }
    }
}